﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using Antu.DataAccess;
namespace Antu.Business.PublicHouse
{
    public class PublicHouseInfo
    {
        private string _connString = "";
        public string ConnString
        {
            get
            {
                return _connString;
            }
            set
            {
                _connString = value;
            }
        }
        public PublicHouseInfo(String conn)
        {
            ConnString=conn;
        }
        /// <summary>
        /// 判断该录入工具的房屋信息是否已经导入过
        /// </summary>
        public void SetPublicHouseState()
        { 
             string strSql = "select * from 申请售房情况 where flag=0";
             DataTable dtTemp;
             SysParams.ConnectionString = ConnString;
             SysParams.OAConnection(false, DatabaseType.Access).RunSql(strSql, out dtTemp);
             foreach (DataRow row in dtTemp.Rows)
             {
                 //由于不同的丘号只能出现一次，因此根据单位编号和丘号来查询
                 strSql = string.Format(@"select a.* from zf_salehouses a,zf_housesale b where a.saleid=b.id 
                           and trim(a.hillno)='{0}' and trim(b.unitno)='{1}'",
                           row["丘号"].ToString().Trim(), row["单位编号"].ToString().Trim());
                 DataTable dtSalehouses;
                 SysParams.OAConnection(false, DatabaseType.Oracle).RunSql(strSql, out dtSalehouses);
                 if (dtSalehouses.Rows.Count > 0)
                 {
                     strSql = string.Format(@"update 申请售房情况 set flag=2 where aiid={0}",row["aiid"].ToString());
                     SysParams.ConnectionString = ConnString;
                     SysParams.OAConnection(false, DatabaseType.Access).RunSql(strSql);
                 }
             }
        }
        /// <summary>
        /// 判断该批次的申请房屋信息，是否有的丘号在系统中曾经办理过
        /// </summary>
        /// <returns></returns>
        public bool SelectRepeatHillno()
        {
            bool isRepeat=false;
            string strSql = "select * from 申请售房情况 where flag=0";
            DataTable dtTemp;
            SysParams.ConnectionString = ConnString;
            SysParams.OAConnection(false, DatabaseType.Access).RunSql(strSql, out dtTemp);
            foreach (DataRow row in dtTemp.Rows)
            { 
             
                 //由于不同的丘号只能出现一次，因此根据单位编号和丘号来查询
                 strSql = string.Format(@"select a.* from zf_salehouses a,zf_housesale b where a.saleid=b.id 
                           and trim(a.hillno)='{0}' and trim(b.unitno)='{1}'",
                           row["丘号"].ToString().Trim(), row["单位编号"].ToString().Trim());
                 DataTable dtSalehouses;
                 SysParams.OAConnection(false, DatabaseType.Oracle).RunSql(strSql, out dtSalehouses);
                 if (dtSalehouses.Rows.Count > 0)
                 {
                     isRepeat = true;
                     break;
                 }
            }
            return isRepeat;
        }
        
    }
}
